//
//  DeathService.m
//  Opper
//
//  Created by Le Dung on 4/16/13.
//  Copyright (c) 2013 LeDung. All rights reserved.
//

#import "DeathService.h"

@interface DeathService ()

@end

@implementation DeathService
@synthesize deathListArray;

-(void)indexPress:(NSString *)stringRespone andTagRespone:(NSInteger)tagR andIndexObject:(NSString *)idRespone andNameRespone:(NSString *)nameRespone
{
    [self.deathList setTitle:nameRespone forState:UIControlStateNormal];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)viewDidAppear:(BOOL)animated
{
    [StyleClass barButtonItemEdit:self left:NO right:NO];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [StyleClass createNavi:self andTitle:@"Autoverzekering"];
    [StyleClass backgroundInblack:self.view];
    [self styleContaint];
    [self buttonTarget];
    [self loadData];
    [self createListCollection];
}

-(void)loadData
{
    self.deathListArray =[[NSMutableArray alloc]init];
        for(Member *unit in [GetData App].profileArray)
    {
        ListObject *listObject =[[ListObject alloc]init];
        listObject.objectName = [[unit.firstName stringByAppendingString:@" "] stringByAppendingString:unit.lastname];
        listObject.objectId =unit.idMember;
        [self.deathListArray addObject:listObject];
        [listObject release];
    }
}
-(void)acceptPress
{
    NSString *functionName =@"setDeath";
    NSMutableDictionary *dictionary =[[[NSMutableDictionary alloc]init] autorelease];
    [dictionary setValue:[GetData App].userAccount.userName forKey:@"username"];
    [dictionary setValue:[GetData App].userAccount.password forKey:@"passwd"];
    [dictionary setValue:self.member.idMember forKey:@"member_id"];
    
    
    NSString *jsonRespones =[GetData sendRequest:functionName andDictionary:dictionary];
    if(![GetData checkError:jsonRespones])
    {
        Document *page=[[[Document alloc]init]autorelease];
        page.contractInfo=self.contracInfo;
        page.member =self.member;
        page.isInstane=1;
        [StyleClass currentScreen:self andDestination:page andHideBackButton:YES];
    }
    else
    {
        [StyleClass warningShow:nil andMassage:[GetData checkMassage:jsonRespones]];
    }
}

-(void)cancelPress
{
    [self.navigationController  popViewControllerAnimated:YES];
}

-(void)buttonTarget
{
    [self.acceptButton addTarget:self action:@selector(acceptPress) forControlEvents:UIControlEventTouchUpInside];
    [self.acceptButton setBackgroundImage:[StyleClass nGreen] forState:UIControlStateNormal];
    
    
    [self.cancelButton addTarget:self action:@selector(cancelPress) forControlEvents:UIControlEventTouchUpInside];
    [self.cancelButton setBackgroundImage:[StyleClass nRed] forState:UIControlStateNormal];
    [self.deathList setBackgroundImage:[StyleClass nList] forState:UIControlStateNormal];
    self.deathList.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    self.deathList.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.deathList addTarget:self action:@selector(listPress) forControlEvents:UIControlEventTouchUpInside];

}

/// 500 > list tag < 600
-(void)createListCollection
{
  ListCollection *deathListView =  [StyleClass listCollection:self.containView andViewLocation:self.deathList andData:deathListArray andTagSender:0];
    deathListView.delegate=self;
    deathListView.tag =500;
}
-(void)listPress
{
    UIView *view = [self.view viewWithTag:500];
    if (view.hidden)
    {
        [view setHidden:NO];
    }
    else
    {
        [view setHidden:YES];
    }

}

-(void)styleContaint
{
    [StyleClass background:self.containView];
    self.containView.layer.shadowColor = [[UIColor blackColor] CGColor];
    self.containView.layer.shadowOffset = CGSizeMake(0.0, 2.0);
    self.containView.layer.shadowOpacity = 1.0f;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [_containView release];
    [_cancelButton release];
    [_acceptButton release];
    [_deathList release];
    [deathListArray release];
    [super dealloc];
}
- (IBAction)deathList:(id)sender {
}
@end
